/// @tags: ODT PersistentSegTree
#include <cstdio>
#include <iostream>
#include <set>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

int const N = 1e5 + 5;

int n, q, s[N], m[N], k[N], b[N], c[N];
ll sum[N];

inline pair<ll, ll> operator+(pair<ll, ll> const &lhs, pair<ll, ll> const &rhs) {
  return make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
}

struct PersistentSegTree {
  struct Node {
    int ls, rs;
    ll val, sum;
  };

  int op, rt[N], cnt;
  Node tr[N * 20];

  void modify(int &x, int y, int l, int r, int pos, int v) {
    tr[x = ++cnt] = tr[y];
    tr[x].val += k[v];
    tr[x].sum = tr[y].sum + m[v] - ((op == 0) ? s[v] : 0);
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid) modify(tr[x].ls, tr[y].ls, l, mid, pos, v);
    else
      modify(tr[x].rs, tr[y].rs, mid + 1, r, pos, v);
  }

  pair<ll, ll> query(int x, int y, int L, int R, int l, int r) {
    if (L <= l && r <= R) return make_pair(tr[y].val - tr[x].val, tr[y].sum - tr[x].sum);
    int mid = (l + r) >> 1;
    pair<ll, ll> ans(0, 0);
    if (L <= mid) ans = ans + query(tr[x].ls, tr[y].ls, L, R, l, mid);
    if (R > mid) ans = ans + query(tr[x].rs, tr[y].rs, L, R, mid + 1, r);
    return ans;
  }
} T[2];

struct Node {
  int l, r, val;
  Node(int l = 0, int r = 0, int val = 0) : l(l), r(r), val(val) {}
  inline bool operator<(Node const &rhs) const { return l < rhs.l; }
};

typedef set<Node>::iterator iter;

set<Node> odt;

inline iter split(int x) {
  iter it = odt.lower_bound(Node(x));
  if (it != odt.end() && it->l == x) return it;
  --it;
  int l = it->l, r = it->r, val = it->val;
  odt.erase(it);
  odt.insert(Node(l, x - 1, val));
  return odt.insert(Node(x, r, val)).first;
}

inline ll query(int t, int x, int y) {
  iter rit = split(y + 1), lit = split(x);
  int l, r, val;
  ll ans = sum[y] - sum[x - 1];
  pair<ll, ll> res;
  for (iter it = lit; it != rit; ++it) {
    l = it->l, r = it->r, val = it->val;
    if (val == 0)
      res = T[0].query(T[0].rt[l - 1], T[0].rt[r], min(N, t - val + 1), N, 0, N);
    else
      res = T[1].query(T[1].rt[l - 1], T[1].rt[r], min(N, t - val + 1), N, 0, N);
    ans += res.first * (t - val) - res.second;
  }
  odt.erase(lit, rit);
  odt.insert(Node(x, y, t));
  return ans;
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> s[i] >> m[i] >> k[i];
  for (int i = 1; i <= n; ++i) {
    b[i] = (k[i] == 0) ? N : (m[i] - s[i]) / k[i] + ((m[i] - s[i]) % k[i] > 0);
    c[i] = (k[i] == 0) ? N : m[i] / k[i] + (m[i] % k[i] > 0);
    sum[i] = sum[i - 1] + m[i];
  }
  T[0].op = 0, T[1].op = 1;
  for (int i = 1; i <= n; ++i) T[0].modify(T[0].rt[i], T[0].rt[i - 1], 0, N, b[i], i);
  for (int i = 1; i <= n; ++i) T[1].modify(T[1].rt[i], T[1].rt[i - 1], 0, N, c[i], i);
  odt.insert(Node(1, n, 0));
  cin >> q;
  for (int t, l, r; q; --q) {
    cin >> t >> l >> r;
    cout << query(t, l, r) << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF453E Little Pony and Lord Tirek.in", "r", stdin);
  freopen("CF453E Little Pony and Lord Tirek.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
